package types

import (
	"ginWork/global"
	"gorm.io/gorm"
)

type Goods struct {
	gorm.Model
	UId            int
	GoodsName      string
	GoodsPrice     int
	GoodsStock     int
	GoodsUrl       string
	GoodsIntroduce string
	GoodsShing     int
	GoodsStatus    int
	GoodsSort      int
}

func (g Goods) Order(orderType int) (goods []Goods, err error) {

	db := global.Db.Table("goods")

	switch orderType {
	case 1:
		db.Order("goods_sort desc")
		break

	case 2:
		db.Order("goods_stock desc")
		break

	case 3:
		db.Order("created_at desc")
		break

	default:
		break
	}

	db.Find(&goods)

	return goods, nil

}
